package org.hot100_1;

public class leetcode95 {
    public int findDuplicate(int[] nums) {
        int slow=0;
        int fast=0;

        while (true){
            //slow执行一步，fast执行两步
            slow = nums[slow];
            fast = nums[fast];
            fast = nums[fast];

            if (slow==fast){
                break;
            }
        }

        slow = 0;
        //当slow=fast时，说明找到了环
        while (slow!=fast){
            slow=nums[slow];
            fast=nums[fast];
        }

        return fast;
    }
}
